<div class="layuimini-container">
    <form id="app-form" class="layui-form layuimini-form">
        <input type="hidden" name="update_time" value="{$row.update_time|default=''}">
        <div class="operate-bar">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit>
                {:lang('common.btn_save')}
            </button>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('user.avatar')}</label>
            <div class="layui-input-block layuimini-upload">
                <input name="avatar" class="layui-input layui-col-xs6" lay-verify="required"
                       placeholder="{:lang('user.avatar_placeholder')}" value="{$row.avatar|default=''}">
                <div class="layuimini-upload-btn">
                    <span><a class="layui-btn" data-upload="avatar" data-upload-exts="png|jpg|jpeg|gif">
                        <i class="fa fa-upload"></i> {:lang('common.btn_upload')}</a></span>
                    <span><a class="layui-btn layui-btn-normal" id="select_avatar" data-upload-select="avatar"><i
                            class="fa fa-list"></i> {:lang('common.btn_choose')}</a></span>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('user.username')}</label>
            <div class="layui-input-block">
                <input type="text" name="username" class="layui-input" lay-verify="required|checkUsername"
                       placeholder="{:lang('common.input')}{:lang('user.username')}"
                       value="{$row.username|default=''}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('user.nickname')}</label>
            <div class="layui-input-block">
                <input type="text" name="nickname" class="layui-input" lay-verify="required"
                       placeholder="{:lang('common.input')}{:lang('user.nickname')}"
                       value="{$row.nickname|default=''}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('user.mobile')}</label>
            <div class="layui-input-block">
                <input type="text" name="mobile" class="layui-input" lay-verify="required"
                       placeholder="{:lang('common.input')}{:lang('user.mobile')}" value="{$row.mobile|default=''}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">{:lang('user.role_ids')}</label>
            <div class="layui-input-block">
                {foreach :roleList() as $key=>$val}
                <input type="checkbox" name="role_ids[{$key}]" lay-skin="primary" title="{$val}"
                       {if in_array($key,$row.role_ids)}checked{/if}>
                {/foreach}
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">{:lang('common.status')}</label>
            <div class="layui-input-block">
                <select name="status" lay-verify="required" default-value="{$row.status|default=''}"
                        data-select-type="status">
                </select>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['myCommon'], function () {
        let $ = layui.jquery
            , form = layui.form
            , myCommon = layui.myCommon
            , userNameInfo = '';
        $('input[name="username"]').blur(function () {
            let data = {username: $(this).val()}, id = "{$row.id|default=''}";
            if (data.username == '') {
                userNameInfo = '';
                return false;
            }
            if (id != '') {
                data.id = id;
            }
            myCommon.request.get({
                url: myCommon.url(CONFIG.CONTROLLER + '/checkUsername')
                , data: data
            }, function (res) {
                userNameInfo = '';
            }, function (res) {
                userNameInfo = res.msg;
                myCommon.msg.error(userNameInfo);
            });
        });
        form.verify({
            checkUsername: function (value) {
                if (userNameInfo != '')
                    return userNameInfo;
            }
        });

        myCommon.listen();
    });
</script>